package com.aftersale.demo.controller;

import com.aftersale.demo.entity.DbLog;
import com.aftersale.demo.entity.LogType;
import com.aftersale.demo.entity.Problem;
import com.aftersale.demo.entity.Result;
import com.aftersale.demo.service.ProblemService;
import com.aftersale.demo.service.ProjectService;
import com.aftersale.demo.utils.ValidGroup;
import com.aliyun.oss.OSSClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 空
 * @date 2023/11/14 16:48
 * @desc
 */
@RestController
@RequestMapping("/client")
@Api(value="客户功能模块")
public class ClientController {

    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProblemService problemService;



    @DbLog(operation = "问题",type = LogType.ADD)
    @PostMapping("/addproblem")
    @ApiOperation("提出问题")
    @PreAuthorize("hasAuthority('problem_create')")
    public Result addProblem(@Validated({ValidGroup.ProblemDescription.class}) Problem problem){
        return problemService.addProblem(problem);
    }

    @GetMapping("/selectproblem")
    @ApiOperation("搜索已提出问题")
    @PreAuthorize("hasAuthority('problem_select')")
    public Result selectProblem(@RequestParam int userId,
                                @RequestParam String name,
                                @RequestParam Integer pageNum,
                                @RequestParam Integer pageSize){
        return problemService.selectProblem(userId,name,pageNum,pageSize);
    }

    @GetMapping("/getproject")
    @ApiOperation("查看已拥有软件")
    @PreAuthorize("hasAuthority('problem_select')")
    public Result getProject(@RequestParam int userId,
                             @RequestParam Integer pageNum,
                             @RequestParam Integer pageSize){
        return projectService.getProject(userId,pageNum,pageSize);
    }

    @GetMapping("/selectproject")
    @ApiOperation("搜索已拥有软件")
    @PreAuthorize("hasAuthority('problem_select')")
    public Result selectProject(@RequestParam int userId,
                                @RequestParam String name,
                                @RequestParam Integer pageNum,
                                @RequestParam Integer pageSize){
        return projectService.selectProject(userId,name,pageNum,pageSize);
    }



    @DbLog(operation = "问题",type = LogType.UPDATE)
    @PutMapping("/updateproblem")
    @ApiOperation("修改已提交问题")
    @PreAuthorize("hasAuthority('problem_update')")
    public Result updateProblem(@RequestBody @Validated({ValidGroup.ProblemDescription.class}) Problem problem){
        return problemService.updateProblem(problem);
    }

    @DbLog(operation = "问题",type = LogType.DELETE)
    @DeleteMapping("/deletemyproblem")
    @PreAuthorize("hasAuthority('my_problem_delete')")
    @ApiOperation(value = "个人售后问题删除接口")
    public Result deleteMyProblem(@RequestParam int problemId){
        return problemService.deleteProblem(problemId);
    }
}
